package edu.neusoft.yiqibike.common.config;

import edu.neusoft.yiqibike.common.entity.mysql.Admin;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.mgt.SessionKey;

import java.util.Objects;

/**
 * User：lyc
 * Date：2018-01-16
 * Time：11:30
 * Description：Mybatis-Plus 公共字段填充
 */
@Slf4j
public class MyMetaObjectHandler extends BaseMetaObjectHandler {
    /**
     * 获取当前登录的管理员信息
     *
     * @return
     */
    @Override
    protected Object getLoginUserInfo() {
        Admin admin;
        try {
            admin = (Admin) SecurityUtils.getSubject().getPrincipal();
        } catch (Exception e) {
            log.error("获取用户信息异常：", e.getMessage());
            return "unkown";
        }
        if (Objects.isNull(admin)) {
            return "未知";
        }
        return String.valueOf(admin.getId());
    }
}
